

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}

function resetText(thefield, textValue){
	if (thefield.value=="")
	thefield.value = textValue
}

$().ready(function() {

	
	 $("#nav li a").click(function() {  
     	
        var hash = window.location.hash.replace('#', '');
   
   		$('ul.subnav').not($(this).parent().find("ul.subnav")).slideUp();
   
		 var pos = $(this).position();
         $(this).parent().find("ul.subnav").css({ "left": (pos.left - 1) + "px", "top": (pos.top + 39) + "px" });
		 $(this).parent().find("ul.subnav").slideToggle("fast");
   
         $(this).parent().find("ul.subnav").hover(function() {}, function(){
				$(this).parent().find("ul.subnav").slideUp();  
         });  
		 }).hover(function() {  
             $(this).addClass("subhover"); 
         }, function(){ 
             $(this).removeClass("subhover");
		
     });
     
     
     $("#nav").mouseleave( function () {
     	$('ul.subnav').slideUp();
     });
     
     
     
     $("a.mailinglist").fancybox({
		'titleShow': false,
        'scrolling':'no',
        'padding':20,
        'onComplete': function() {
	    	$("#email_address").focus();
		},
        'onClosed'		: function() {
            $("label.error").hide();
            $("#email_address").val(''); 
        }
	});
    
    $("#mailinglist").bind("submit", function() {
    
    	var validator = $("#mailinglist").validate({
        	errorPlacement: function(error, element) {
                error.appendTo( element.prev('label') );
            }
        });
        
      var vForm = $("#mailinglist").validate().form();        
    
   	if (vForm == false) {
    		validator.showErrors();
            
            return false;
        } 

	$.fancybox.showActivity();
    
        $.ajax({
            type		: "POST",
            cache	: false,
            url		: "/mailinglist.cfm",
            data		: $(this).serializeArray(),
            success: function(data) {
                $.fancybox(data, {
                	'scrolling':'no'
                });
                $("#email_address").val(''); 
            }
        });
    
        return false;
    }); 
    
    
     
     

         $('#masthead').cycle({
            fx: 'fade',
            speed: 1000,
            timeout: 8000
         });
		
        $('.hearsermon').popup({  
             width: 480,  
             height: 500,
             titlebar: false,
		    status: false,
		    resizable: false,
		    toolbar: false,
		    scrollbars: false,
		    menubar: false  
         }); 
         
         $("a.video").click(function() {
			$.fancybox({
                'padding'		: 10,
                'autoScale'		: false,
                'titleShow' : false,
                'title'			: 'Sojourn Community Church - A Look Back',
                'width'		: 680,
                'height'		: 495,
                'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type'			: 'swf',
                'swf'			: {
                     'wmode'		: 'transparent',
                    'allowfullscreen'	: 'true'
              }
		});

            return false;
        });  
        
        
        $("a.downloadsermon").toggle(function() {
          $("#sermons").slideDown("fast");
        }, function() {
          $("#sermons").slideUp("fast");
        });
        
        $("#sermons a").click( function () {
        	$("a.downloadsermon").click();
        });
        
    

});